﻿using Entitas;
using UnityEngine;

public class RotSystem : IExecuteSystem
{
    private readonly Contexts           contexts;
    private readonly IGroup<GameEntity> group;

    public RotSystem (Contexts contexts)
    {
        this.contexts = contexts;
        group = contexts.game.GetGroup (GameMatcher.AllOf (
            GameMatcher.RotComp,
            GameMatcher.ViewComp
        ));
    }

    public void Execute ()
    {
        foreach (var entity in group.GetEntities ())
        {
            var angle = entity.rotComp.angle;
            entity.viewComp.view.transform.rotation = Quaternion.Euler (0, 0, angle);
        }
    }
}